<script setup>
import{ ref } from 'vue';
import { useRouter } from 'vue-router';
import axios from "axios";
import {showToast} from "vant";
const router = useRouter();
const users = ref([
  {userId:1,name:'张三',description:'你们好你你你你你你你你你你你你你您那你你你你你你你',followersCount:3000000,imageUrl:""}
]);
const loading = ref(false);
const finished = ref(false);
const onLoad = () => {
  axios({
    method: 'get', // post  get
    url: 'http://localhost:9094/user/findAllFollows'
  }).then(
      (data) => {
        console.log(JSON.stringify(data))
        console.log("获取处理器的数据：" + JSON.stringify(data.data))
        var r = data.data;

        // 加载状态结束
        loading.value = false;
        finished.value = true

        if (r.code == 0) {
          showToast("查询成功");
          users.value = r.data;// 初始化界面
        } else {
          showToast("查询失败");
        }


      })
      .catch(
          function () {
            alert("服务器错误")
          }
      )
};

const toAsk=()=> {
 router.push('/help');
}
const onClickLeft=()=>{
  router.push('/my');
}
</script>

<template>
<h1>我叫喻文波</h1>
  <van-nav-bar
      title="我的消息"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
  />
  <van-tabs v-model="active" sticky>
    <van-tab title="我的求助">
      <van-cell-group>
        <van-cell title="稻林纸犀牛的用来快题设计合适吗?" is-link to="">
          <template #right-icon>
            <van-icon name="arrow" />
          </template>
        </van-cell>
      </van-cell-group>
      <van-button type="primary" block @click="toAsk">发布求助</van-button>
    </van-tab>

      <van-tab title="关注">
        <van-list
            v-model:loading="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="onLoad"
        >
          <van-cell
              v-for="user in users"
              :key="user.userId"
              :title="user.username"
              :label="user.description"
              :is-link="false"
          >
            <template #icon>
              <van-image :src="user.imageUrl" width="40" height="40" round />
            </template>
            <template #label>
              <div>{{user.description}}</div>
              <div>粉丝数：{{user.followersCount}}万</div>
            </template>
            <template #right-icon>
              <van-button size="small" type="primary" @click="followUser(user.userId)">
                {{ user.followed ? '已关注' : '关注' }}
              </van-button>
            </template>
          </van-cell>
        </van-list>
      </van-tab>

  </van-tabs>
</template>

<style scoped>

</style>